package demo.dataSource;

import com.alibaba.druid.pool.DruidDataSource;

import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.SQLException;

public class DataSource01 {
    public static void main(String[] args) throws SQLException {
        //创见连接池对象
        /*DataSource dataSource=new DruidDataSource();
        //第一种方法：强转
        ((DruidDataSource)dataSource).setDriverClassName("com.mysql.cj.jdbc.Driver");
        ((DruidDataSource)dataSource).setUrl("jdbc:mysql://127.0.0.1/db1");
        ((DruidDataSource)dataSource).setUsername("root");
        ((DruidDataSource)dataSource).setPassword("123456");*/

        DataSource dataSource;
        DruidDataSource druidDataSource = new DruidDataSource();
        druidDataSource.setDriverClassName("com.mysql.cj.jdbc.Driver");
        druidDataSource.setUrl("jdbc:mysql://127.0.0.1/db1");
        druidDataSource.setUsername("root");
        druidDataSource.setPassword("123456");


        dataSource=druidDataSource;


        Connection connection = dataSource.getConnection();
        System.out.println(connection);
        connection.close();
    }
}
